package edu.washington.ling.syntric.struct.rule;

import edu.washington.ling.syntric.struct.tree.Token;

public class BiDSPattern implements Comparable<BiDSPattern>{
	private Token dsDependent;
	private Token dsHead;
	private Boolean headFinal;
	
	public BiDSPattern(Token child, Token parent) {
		dsDependent = child;
		dsHead = parent;
		headFinal = null;
	}
	public Token getDSDependent() {
		return dsDependent;
	}
	public Token getDSHead() {
		return dsHead;
	}
	public void setHeadFinal(boolean b) {
		headFinal = Boolean.valueOf(b);
	}
	public boolean hasHeadOrder() {
		return (headFinal != null);
	}
	public boolean isHeadFinal() {
		return headFinal.booleanValue();
	}
	public boolean equals(Object other){
		if (this == other){
			return true;
		}
		if (!(other instanceof BiDSPattern)) {
			return false;
		}
		BiDSPattern otherPattern = (BiDSPattern) other;
		return (dsDependent.equals(otherPattern.dsDependent) && dsHead.equals(otherPattern.dsHead) 
				&& (headFinal == null ? otherPattern.headFinal == null
				: (headFinal.equals(otherPattern.headFinal))));
	}
	public int hashCode() {
		return 17*dsDependent.hashCode() + 31*dsHead.hashCode() + 
				(headFinal == null ? 0 : headFinal.hashCode());
	}
	@Override
	public int compareTo(BiDSPattern otherPatt) {
		int dsDependentCmp = dsDependent.compareTo(otherPatt.dsDependent);
		return (dsDependentCmp != 0 ? dsDependentCmp :
				dsHead.compareTo(otherPatt.dsHead));
	}
}
